using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using System.Web.Security;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectBinhLuanVideo()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO
			};
			return View(CreateViewModel(data));
		}


		public ActionResult SelectBinhLuanVideoByIDAlbum(int idalbum, int page = 1)
		{
			var data = new DataTransferViewModel
			{
				IDAlbum = idalbum,
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO,
				CurrentPage = page
			};
			return View("SelectBinhLuanVideo", CreateViewModel(data));
		}

		public ActionResult SelectBinhLuanVideoByIDAlbumPaging(int idalbum, int page = 1)
		{
			var data = new DataTransferViewModel
			{
				IDAlbum = idalbum,
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListBinhLuanVideo", CreateViewModel(data));
		}


		public ActionResult DeleteBinhLuanVideo(int id, int page = 1)
		{
			var result = _repBinhLuanVideo.Delete(id);
			var data = new DataTransferViewModel
			{
				InfoText = result ? "Item has been deleted" : "Cannot delete item!",
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO,
				CurrentPage = page
			};
			return View("SelectBinhLuanVideo", CreateViewModel(data));
		}

		public ActionResult EditBinhLuanVideo(int page, int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO,
				CurrentPage = page,
				IntID = id
			};
			return PartialView("Templates/TH_EditBinhLuanVideo", CreateViewModel(data));
		}

		public ActionResult CancelEditingBinhLuanVideo(int page)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListBinhLuanVideo", CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateBinhLuanVideo(FormCollection forms)
		{
			string id = forms.GetValues("BinhLuanVideo_ID")[0];
			string idalbum = forms.GetValues("BinhLuanVideo_IDAlbum")[0];
			string noidung = forms.GetValues("BinhLuanVideo_NoiDung")[0];
			string tennguoibinhluan = forms.GetValues("BinhLuanVideo_TenNguoiBinhLuan")[0];
			string ngaybinhluan = forms.GetValues("BinhLuanVideo_NgayBinhLuan")[0];
			var binhluanvideo = _repBinhLuanVideo.SelectByID(int.Parse(id));
			binhluanvideo.IDAlbum = int.Parse(idalbum.Replace(".", "").Replace(",", ""));
			binhluanvideo.NoiDung = noidung;
			binhluanvideo.TenNguoiBinhLuan = tennguoibinhluan;
			binhluanvideo.NgayBinhLuan = DateTime.Now;
			var result = _repBinhLuanVideo.Save();
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO,
			};
			return View("SelectBinhLuanVideo", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertBinhLuanVideo(FormCollection forms)
		{
			string idalbum = forms.GetValues("BinhLuanVideo_IDAlbum")[0];
			string noidung = forms.GetValues("BinhLuanVideo_NoiDung")[0];
			string tennguoibinhluan = forms.GetValues("BinhLuanVideo_TenNguoiBinhLuan")[0];
			string ngaybinhluan = forms.GetValues("BinhLuanVideo_NgayBinhLuan")[0];
			var newItem = new BinhLuanVideo
			{
				IDAlbum = int.Parse(idalbum),
				NoiDung = noidung,
				TenNguoiBinhLuan = tennguoibinhluan,
				NgayBinhLuan = ngaybinhluan == "" ? DateTime.Now : DateTime.Parse(ngaybinhluan)
			};
			var result = _repBinhLuanVideo.Insert(newItem);
			var data = new DataTransferViewModel
			{
				IDAlbum = int.Parse(idalbum),
				EnumViewModelType = EnumViewModel.ADMIN_BINHLUANVIDEO,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectBinhLuanVideo", CreateViewModel(data));
		}


	}
}